﻿using System;
using System.Linq.Expressions;

namespace MyFramework.Command
{
    /// <summary>
    /// expression extensions
    /// </summary>
    public static class ExpressionExtensions
    {
        /// <summary>
        /// Gets the name of the property.
        /// </summary>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="projection">The projection.</param>
        /// <returns></returns>
        public static string GetPropertyName<TProperty>(this Expression<Func<TProperty>> projection)
        {
            var memberExpression = (MemberExpression)projection.Body;
            return memberExpression.Member.Name;
        }
    }
}
